/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EL_PROTOCOL_DISCOVERY_COMMAND_HANDLER_H
#define EL_PROTOCOL_DISCOVERY_COMMAND_HANDLER_H

#include <string>
#include <functional>
#include <unordered_map>
#include <nlohmann/json.hpp>
#include "command_handler_base.h"

namespace El {
namespace Protocol {

/**
 * @brief 发现服务相关命令处理器
 * 负责 discovery.search / discovery.setIp 等设备发现协议
 */
class DiscoveryCommandHandler : public CommandHandlerBase {
public:
    DiscoveryCommandHandler() = default;
    ~DiscoveryCommandHandler() = default;

    DiscoveryCommandHandler(const DiscoveryCommandHandler &) = delete;
    DiscoveryCommandHandler &operator=(const DiscoveryCommandHandler &) = delete;

    /**
     * @brief 注册发现服务相关方法处理器到方法映射表
     * @param method_handlers 目标方法映射表
     */
    void RegisterMethodHandlers(
        std::unordered_map<std::string, std::function<nlohmann::json(const std::string &, const nlohmann::json &)>>
            &method_handlers);

private:
    // 发现服务相关方法处理器
    nlohmann::json HandleDiscoverySearch(const std::string &id, const nlohmann::json &params);
    nlohmann::json HandleDiscoverySetIp(const std::string &id, const nlohmann::json &params);
};

} // namespace Protocol
} // namespace El

#endif // EL_PROTOCOL_DISCOVERY_COMMAND_HANDLER_H

